<template>
    <div class="vertical-steps">
        <div v-for="(step, index) in steps" :key="index" class="step"
            :class="{ active: current === index, completed: index < current }">
            <div class="step-top-box">
                <div class="user-box">
                    {{ step.name ? step.name.charAt(0,) : '' }}
                    <div class="status-icon">
                        <img src="@/assets/images/success.svg" class="status-icon" v-if="step.status === 'success'" />
                        <img src="@/assets/images/waring.svg" class="status-icon" v-if="step.status === 'waring'" />
                        <img src="@/assets/images/pending.svg" class="status-icon" v-if="step.status === 'pending'" />
                    </div>
                </div>
            </div>
            <div class="bottom-content">
                <div class="step-content">
                    <div class="step-inline">
                        <span class="stepName">
                            <el-tooltip class="box-item" effect="dark" :content="step.name" placement="top-start">
                                {{ step.name }}
                                <span class="stepAction"> {{ step.stepAction }}</span>
                            </el-tooltip>
                        </span>
                        <span class="statusName" :style="{ color: step.statusColor }" v-if="step.statusName != '审批中'">{{ step.statusName }}</span>
                    </div>
                    <div class="step-inline">
                        <span class="step-role">{{ step.position }}</span>
                        <span>{{ step.time }}</span>
                    </div>
                </div>
                <div class="step-description" :style="{ backgroundColor: styleColor }">
                    审批意见: {{ step.description }}
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref } from 'vue';

/**
 * 审批状态 枚举
 */
enum stepStatus {
    success = 'success',
    waring = 'waring',
    pending = 'pending',
}

/**
 * stepObject 接口定义了一个步骤对象，包含以下属性：
 *
 * - label: string, // 步骤名称，非必填
 * - description: string, // 审批意见
 * - name: string, // 审批人
 * - status: stepStatus, // 审批状态
 * - position: string, // 审批人职位
 * - time: string, // 审批时间
 * - stepAction: string, // 审批动作
 * - statusName: string, // 审批状态名称
 * - statusColor: string, // 审批状态颜色
 */
interface stepObject {
    label?: string,
    description?: string,
    name: string,
    status: stepStatus,
    position: string,
    time: string,
    stepAction: string,
    statusName: string,
    statusColor: string,
}
const props = defineProps({
    steps: {
        type: Array<stepObject>,
        required: true,
    },
    current: {
        type: Number,
        default: 0,
    },
    styleColor: {
        type: String,
        default: '#f5f5f5',
    }
});



</script>

<style lang="scss" scoped>
.vertical-steps {
    display: flex;
    // flex-direction: column;
    align-items: center;
    position: relative;
    width: 100%;
    overflow-x: auto;
    /* Adjust as needed */
}

.bottom-content {
    height: auto;
    margin: 5px;
    padding: 5px;
    background: #FFFFFF;
    box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
}

.user-box {
    width: 54px;
    height: 54px;
    background: #4A78F4;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 24px;
    color: #FFFFFF;
    position: relative;
    z-index: 2;

    .status-icon {
        position: absolute;
        bottom: 0;
        right: -2px;
        width: 18px;
        height: 18px;
    }
}

.step {
    position: relative;
    margin: 5px 0;
    width: 100%;
}

.step-top-box {
    display: flex;
}

.step:not(:last-child)::after {
    content: '';
    position: absolute;
    width: calc(100% - 10px);
    height: 2px;
    top: 14%;
    left: 7%;
    /* Adjust height as needed */
    border-top: 2px dashed #C8CCD5;
    /* Dashed line style */
}

.step-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ccc;
    color: #fff;
    margin-right: 12px;
    font-weight: bold;
}

.step.active .step-icon {
    background-color: #007bff;
}

.step.completed .step-icon {
    background-color: #28a745;
}

.step-content {
    // display: flex;
    flex-direction: column;
    width: 95%;
    height: 60px;
    margin: 0px 5px;

    .step-inline {
        height: 30px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 0.625vw;

        .stepName {
            font-weight: bold;
            font-size: 1.04vw;
            color: #333333;
            letter-spacing: 1px;
            width: 10vw;
            text-overflow: ellipsis;
            /* 显示省略号 */
            white-space: nowrap;
            /* 防止换行 */
            overflow: hidden;

            /* 隐藏溢出内容 */
            .stepAction {
                font-size: 16px;
            }
        }

        .statusName {
            font-weight: 500;
            font-size: 1.04vw;
            color: #999999;
        }
    }
}

.step-label {
    font-size: 14px;
}

.step-description {
    margin-left: 48px;
    width: 70%;
    padding: 10px;
    min-height: 40px;
    // background: #e0f7fa;
    // background: #f5f5f5;
    // background:#f9f3e3;
    border-radius: 8px;
    font-size: 0.625vw;
    color: #666666;
    text-indent: 2ch;
}
</style>